package cn.boyu.advice;

import cn.boyu.exception.LogicException;
import cn.boyu.result.AjaxResult;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class CommonExceptionHandler {

    /*逻辑异常*/
    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public Object handlerLogicException(LogicException e) {
        AjaxResult error = AjaxResult.error(e.getMessage());
        return error;

    }
    /*运行时异常*/
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Object handlerLogicException(RuntimeException e) {
        AjaxResult error = AjaxResult.error("系统错误");
        return error;

    }


}
